#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
int main()
{
    int a,b;
    int f[11]={1,2,4,8,1,3,6,1,2,5};
    cin>>a>>b;
    int e;
    bool flag=false;
    for(e=a+1;e<=62;e++)
    {  if(e==46){if(b==7){cout<<e<<endl;flag=true;break;} else continue;}
       if(e==56){if(b==7){cout<<e<<endl;flag=true;break;} else continue;}
       if(e==53){if(b==9){cout<<e<<endl;flag=true;break;} else continue;}
       if(f[e%10]==b&&e!=46&&e!=56&&e!=53) {cout<<e<<endl;flag=true;break;}
       }
    if(!flag) cout<<0<<endl;
    //system("pause");
    return 0;
}
          
